<?php
$this->useClass("Action_Community_FeedHandler");
class Action_Community_ShowAlphabet extends Action_Community_FeedHandler
{
	public function getFeedModel() {
		$this->rh->UseClass("AggregatedModel_Feed_FeedInterface");
		$this->rh->UseClass("AggregatedModel_Feed_ReaderItems");

		return new AggregatedModel_Feed_ReaderItems();
	}

	public function init() {
		parent::init();
		$this->m_tdi = $this->ctx->mm->getModel("Tdi", "m");

		$tdi_oids = array();
		foreach ($this->aa->acl_data['tdi_list'] as $tdi) $tdi_oids[] = $tdi['id_object'];
		$this->tdi_types = $this->m_tdi->getSections($tdi_oids);

	}

	public function getWidgetsConfig ()
	{

		$widgets = array();

		$widgets[] = array (
			'name' => 'CreateBtnWidget',
			'params' => array(
				'widget_position' => 'createbtn',
				'widget_view' => 'WG_CreateBtnWidget',
			),
		);

		$widgets[] = array (
			'name' => 'Feed_DoctypesMenuWidget',
			'params' => array(
				'widget_position' => 'tags',
				'widget_view' => 'WG_Feed_DoctypesMenuWidget',
			),
		);

		$widgets[] = array (
			'name' => 'TagsWidget',
			'params' => array(
				'community_oid' => $this->aa->acl_data['comity_oid'],
				'tdi_oid'=> $this->aa->acl_data['tdi_oid'],
				'tag' => $this->getParam('tag'),
				'widget_position' => 'tags',
				'widget_view' => 'WG_TagsWidget',
				'view_type' => 'files',
			),
		);

		$widgets[] = array (
			'name' => 'RssWidget',
			'params' => array(
				'widget_view' => 'WG_RssWidget',
				'widget_position' => 'tags',
			),
		);

		return $widgets;
	} // end of function getWidgetsConfig


	public function process ()
	{
		$aa = &$this->aa;
		$aa->checkDeletions(array($this, "shutdown") );

		$this->setParam("struct_type", "letters");
		$this->model->doStuff();

		$response = $this->rh->response;
		$view = $this->rh->views->findByName('alphabet');
		$view->data = $aa->template_data;

		$view->data['can_create'] = $aa->is_granted(array('item_create', 'item_create_premod'));

		$view->data['letters'] = $this->model->getItems();

		if ($view->data['letters']) {
		} else $view->data['message'] = "В этой ленте нет сообщений.";

		$view->data['page'] = $this->getPagerInfo();
		$view->data['items_remaining'] = $view->data['page']['items_remaining'];

		$this->renderFilters($view);

		$view->data['__widgets__'] = $this->widgets;

		// генерация урл адресов
		$this->rh->UseClass("RL_URLGenerator");
		$ug = new RL_URLGenerator($this->rh->router->getLastMatched()); //$this->rh->router->getRule('object_undelete')
		$ug->setRouter($this->rh->router);
		$ug->setParams($this->params);

		// постраничная листалка без ajax
		if (isset($view->data['page']['prev'])) {
			$ug->setGet(array_merge($this->rh->GET, array("p"=>$view->data['page']['prev'])));
			$view->data["prev_url"] = $ug->generateUrl();
		}

		if (isset($view->data['page']['next'])) {
			$ug->setGet(array_merge($this->rh->GET, array("p"=>$view->data['page']['next'])));
			$view->data["next_url"] = $ug->generateUrl();
		}

		$this->rh->response->setContent( $view );

		// -- touch visitor stat -- {{{
		// visit tdi
		$this->ctx->mm->getModel("Visitable", "m")->getVisitable('Tdi')->visit();
		//
		// -- touch visitor stat -- }}}

	} // end of function execute

}
